﻿namespace DomainServices.Tools.Pdb.SymStore
{
    using System;
    using System.Diagnostics.SymbolStore;
    using System.Text;

    internal class SymbolDocument : ISymbolDocument
    {
        private ISymUnmanagedDocument m_unmanagedDocument;

        internal SymbolDocument(ISymUnmanagedDocument document)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            this.m_unmanagedDocument = document;
        }

        public int FindClosestLine(int line)
        {
            int pRetVal = 0;
            this.m_unmanagedDocument.FindClosestLine(line, out pRetVal);
            return pRetVal;
        }

        public byte[] GetCheckSum()
        {
            int pcData = 0;
            this.m_unmanagedDocument.GetCheckSum(0, out pcData, null);
            byte[] data = new byte[pcData];
            this.m_unmanagedDocument.GetCheckSum(pcData, out pcData, data);
            return data;
        }

        public byte[] GetSourceRange(int startLine, int startColumn, int endLine, int endColumn)
        {
            int pcSourceBytes = 0;
            this.m_unmanagedDocument.GetSourceRange(startLine, startColumn, endLine, endColumn, 0, out pcSourceBytes, null);
            byte[] source = new byte[pcSourceBytes];
            this.m_unmanagedDocument.GetSourceRange(startLine, startColumn, endLine, endColumn, pcSourceBytes, out pcSourceBytes, source);
            return source;
        }

        public Guid CheckSumAlgorithmId
        {
            get
            {
                Guid pRetVal = new Guid();
                this.m_unmanagedDocument.GetCheckSumAlgorithmId(ref pRetVal);
                return pRetVal;
            }
        }

        public Guid DocumentType
        {
            get
            {
                Guid pRetVal = new Guid();
                this.m_unmanagedDocument.GetDocumentType(ref pRetVal);
                return pRetVal;
            }
        }

        public bool HasEmbeddedSource
        {
            get
            {
                bool pRetVal = false;
                this.m_unmanagedDocument.HasEmbeddedSource(out pRetVal);
                return pRetVal;
            }
        }

        internal ISymUnmanagedDocument InternalDocument
        {
            get
            {
                return this.m_unmanagedDocument;
            }
        }

        public Guid Language
        {
            get
            {
                Guid pRetVal = new Guid();
                this.m_unmanagedDocument.GetLanguage(ref pRetVal);
                return pRetVal;
            }
        }

        public Guid LanguageVendor
        {
            get
            {
                Guid pRetVal = new Guid();
                this.m_unmanagedDocument.GetLanguageVendor(ref pRetVal);
                return pRetVal;
            }
        }

        public int SourceLength
        {
            get
            {
                int pRetVal = 0;
                this.m_unmanagedDocument.GetSourceLength(out pRetVal);
                return pRetVal;
            }
        }

        public string URL
        {
            get
            {
                int num;
                this.m_unmanagedDocument.GetURL(0, out num, null);
                StringBuilder szUrl = new StringBuilder(num);
                this.m_unmanagedDocument.GetURL(num, out num, szUrl);
                return szUrl.ToString();
            }
        }
    }
}

